package tool

import (
	"encoding/json"
	"fmt"
	"runtime"
	"time"
)

func JsonLog(v interface{}) {
	var l = make([]bool, 3)
	println("\r\n")

	println("#####JSON_LOGGER [" + fmt.Sprintf("%d", time.Now().UnixNano()) + "]")
	println(GetDateFromTimeYMDHIS(time.Now(), "/", ":", " "))
	println(GetDateYMDHIS("/", ":", " "))
	for index, _ := range l {
		_, file, line, _ := runtime.Caller(2 - index + 1)
		println(fmt.Sprintf("[%d] %s:%d\t", index, file, line))
	}
	switch v.(type) {
	case string:
		println("data type = string")
		println(v.(string))
	case []byte:
		println("data type = []byte",len(v.([]byte)))
		println(string(v.([]byte)))
	default:
		println("data type = unknown")
		str, _ := json.Marshal(v)
		println(string(str) + "\r\n\r\n")
	}
}

func GetLine() int {
	_, _, line, _ := runtime.Caller(1)
	return line
}

func ThisLine() int {
	return GetLine()
}

func PrintLine() {
	_, _, line, _ := runtime.Caller(1)
	println(fmt.Sprintf("Line:%d", line))
}
